<template>
    <div>
        <Card>
            <!--搜索框-->
            <Form :model="search" ref="form1" label-position="right" :label-width="90" inline>
                <FormItem label="处理状态" prop="name">
                    <div class="filters-input">
                        <el-select v-model="search.state" clearable placeholder="请选择处理状态">
                            <el-option v-for="item in options" :value="item.value" :key="item.value" :label="item.label">
                            </el-option>
                        </el-select>
                    </div>
                </FormItem>

                <FormItem label="起始日期" prop="hainaStatus">
                    <div class="filters-input">
                        <DatePicker type="daterange" v-model="search.theDate" placeholder="请选择日期"></DatePicker>
                    </div>
                </FormItem>

                <FormItem>
                    <Button type="primary" icon="ios-search" @click="handleQuery('form1')">搜索</Button>
                </FormItem>
            </Form>

            <!--内容 表单-->

            <el-table stripe border :loading="tableLoading" :data="tableData" style="width: 100%">
                <template slot="empty">暂无数据</template>
                <el-table-column prop="id" label="ID"></el-table-column>
                <el-table-column prop="content" label="投诉建议内容"></el-table-column>
                <el-table-column label="投诉建议来源">
                    <template slot-scope="scope">
                        <p v-if="scope.row.typeInt == 2" style="color:green">业主</p>
                        <p v-if="scope.row.typeInt == 4" style="color:blue">员工</p>
                    </template>
                </el-table-column>
                <el-table-column prop="telphone" label="联系电话"></el-table-column>
                <el-table-column label="状态">
                    <template slot-scope="scope">
                        <p v-if="scope.row.state == 1" style="color:red">未处理</p>
                        <p v-if="scope.row.state == 2" style="color:blue">处理中</p>
                        <p v-if="scope.row.state == 3" style="color:green">已完成</p>
                    </template>
                </el-table-column>
                <el-table-column prop="createTime" label="提交时间"></el-table-column>
                <el-table-column prop="finishTime" label="完成时间"></el-table-column>
                <el-table-column label="操作" width="150" align="center">
                    <template slot-scope="scope">
                        <el-button size="mini" type="primary" @click="HandleState( scope.row.id)"
                                   v-if="scope.row.state == 1">确认事务
                        </el-button>
                        <el-button size="mini" type="warning" @click="HandleState( scope.row.id)"
                                   v-if="scope.row.state == 2">完成处理
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

            <Page style="margin: 10px 0;" :total="pageTotal" :current="pageNum" :page-size="pageSize" show-total
                  show-sizer show-elevator @on-change="handlePage" @on-page-size-change='handlePageSize'>
            </Page>

        </Card>
    </div>
</template>


<script>
    let loadData = function () {
        if (this.tableLoading) return;
        this.tableLoading = true;
        let params = this.search;
        params.pageNum = this.pageNum;
        params.pageSize = this.pageSize;
        params.typeInt = 2;

        //与后台交换数据
        this.postRequest("/api/reporting/loadDataTwo", params).then(res => {
            this.tableLoading = false;
            if (res.code == 20000) {
                this.tableData = res.data.list;
                this.pageTotal = res.data.total;
            } else {
                this.tableData = [];
                this.$Message.error({
                    content: res.message,
                    duration: 5
                });
            }
        });
    };
    import moment from "moment"

    export default {
        data() {
            return {
                search: {},
                pageSize: "",
                pageNum: 1,
                //每页数量
                pageSize: 10,
                //总数
                pageTotal: 0,
                //数据表格隐藏那个状态
                tableLoading: false,
                options: [
                    {
                        value: "1",
                        label: "未处理"
                    },
                    {
                        value: "2",
                        label: "处理中"
                    },
                    {
                        value: "3",
                        label: "已处理"
                    }
                ],
                tableData: []
            };
        },

        created: function () {
            //加载数据
            this.loadData();
        },
        methods: {
            loadData,
            handlePage(value) {
                this.pageNum = value;
                this.loadData();
            },
            handlePageSize(value) {
                this.pageSize = value;
                this.loadData();
            },
            //查询
            handleQuery(name) {
                this.search.pageNum = 1;
                this.$refs[name].validate(valid => {
                    if (valid) {
                        this.search.theDate[0] = moment(this.search.theDate[0]).format("YYYY-MM-DD");
                        this.search.theDate[1] = moment(this.search.theDate[1]).format("YYYY-MM-DD");
                        console.log(this.search);
                        this.loadData();
                    }
                });
            },
            //处理状态
            HandleState(id) {
                this.getRequest("/api/reporting/updateState?id=" + id).then(res => {
                    console.log(res);
                    this.tableLoading = false;
                    if (res.code == 20000) {
                        this.$Message.success("修改状态成功!");
                        this.pageNum = 1;
                        this.loadData();
                    } else {
                        this.$Message.error({
                            content: res.message,
                            duration: 50
                        });
                    }
                });
            }
        }
    };
</script>
